<template>
  审批人：
  <el-select v-model="position_selected" placeholder="请选择职位">
   <el-option v-for="(item, key) in positionlist" :key="key" :value="item.id" :label="item.name" >
   </el-option>
  </el-select>
  顺序：
  <el-input v-model="order" placeholder="请输入顺序"></el-input>
  <el-button type="primary" @click="submit">创建</el-button>
  <el-button type="primary" @click="router.push('/admin')">创建结束</el-button>
</template>

<script setup>
  import { ref, onMounted } from "vue"
  import { useRoute, useRouter } from "vue-router"
  import http from "../http"

  const route = useRoute()
  const router = useRouter()

  let id = route.query.id

  let positionlist = ref([])

  let order = ref("")

  let position_selected = ref("")

  const getpositionlist = () =>{
    http.get(`myadmin/position_list/`)
    .then(res => {
      console.log(res)
      positionlist.value = res.data
    })
    .catch(error=>{
      console.log(error)
    })
  }

  const submit = () =>{
    http.post(`http://127.0.0.1:8000/workflow/create_workflow_approval_node/`, {"workflow": id, "position": position_selected.value, "level": order.value})
    .then(res => {
      console.log(res)
      alert("添加成功")
    })
    .catch(error=>{
      console.log(error)
    })
  }

  onMounted(() => {
    getpositionlist()
  })
</script>
